package com.jiexin.controller;

import com.google.common.collect.Lists;
import com.jiexin.beans.DescPageQuery;
import com.jiexin.beans.DescPageResult;
import com.jiexin.common.JsonData;
import com.jiexin.dao.SysAclMapper;
import com.jiexin.exception.ParamException;
import com.jiexin.model.PlmDescription;
import com.jiexin.model.PlmWorkFlow;
import com.jiexin.param.DescriptionParam;
import com.jiexin.service.PlmDescriptionService;
import com.jiexin.service.PlmWorkFlowService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Jay_Liu
 * @Description:
 * @Date: Created in 20:25 2018/5/28 0028
 * @Modified By:
 */
@Controller
@RequestMapping("/plm/desc")
public class PlmDescriptionController {

    @Resource
    PlmDescriptionService plmDescriptionService;

    @Resource
    SysAclMapper sysAclMapper;

    @Resource
    private PlmWorkFlowService plmWorkFlowService;

    @RequestMapping("/desc.page")
    public ModelAndView page(){
        return new ModelAndView("desc");
    }

    @RequestMapping("/page.json")
    @ResponseBody
    public DescPageResult list(DescPageQuery pageQ) {
        DescPageResult<PlmDescription> pageResult = plmDescriptionService.getPage(pageQ);
        return pageResult;
    }

    @RequestMapping("/save.json")
    @ResponseBody
    //保存
    public JsonData saveDesc(DescriptionParam param) {
        plmDescriptionService.save(param);
        return JsonData.success();
    }

    @RequestMapping("/update.json")
    @ResponseBody
    //更新
    public JsonData updateDesc(DescriptionParam param) {
        plmDescriptionService.update(param);
        return JsonData.success();
    }

    @RequestMapping("/delete.json")
    @ResponseBody
    //删除
    public JsonData deleteDescription(@RequestParam("descriptionId") List<Integer> descriptionIds) {
        plmDescriptionService.delete(descriptionIds);
        return JsonData.success();
    }

}
